<?php
declare(strict_types=1);

namespace Service\Consumer\YunCangConsumer\Router;
use Service\BaseService;
use Service\EsService\EsPublishMsgService;
use App\Model\BbcModel\MnStoreGoods;
use App\Model\BbcModel\Goods;
use Service\Code\Normal;

/**
 * 商品全量下架操作
 * @author chenshubo
 */
class goodsBatchDown extends BaseService
{
    /**
     * 接收消费数据
     * @param int $sid
     * @param int $cid
     * @param array $data
     * @param string $messageId
     * @param int $IsFinished
     */
    public function consumer(int $sid,int $cid,array $data,string $messageId,int $IsFinished)
    {
//        try {
//            //下架店铺商品
//            $table = MnStoreGoods::instance()->getTable();
//            MnStoreGoods::instance()
//            ->from("{$table} as lmsg")
//            ->join('ly_goods as lg','lmsg.goods_id','=','lg.id')
//            ->where('lg.cid',$cid)
//            ->where('lg.is_trade',0)
//            ->where('lg.df',0)
//            ->update([
//                'lmsg.df'   => 1,
//                'lmsg.md'   => time(),
//            ]);
//
//            Goods::instance()->where('cid',$cid)->where('is_trade',0)->where('df',0)->update([
//                'df'    => 1,
//                'md'    => time(),
//            ]);
//            EsPublishMsgService::instance()->pushNew($cid,'channel','deleteAll');
//            EsPublishMsgService::instance()->pushNew($cid,'store','deleteAll');
//            return Normal::returnCode(Normal::SUC,"处理完成");
//        } catch ( \Throwable $th ) {
//            $error = [
//                'error'         => $th->getMessage(),
//                'errorFile'     => $th->getFile(),
//                'errorLine'     => $th->getLine(),
//            ];
//            $_class_name = __CLASS__;
//            return Normal::returnCode(Normal::FAIL,"{$_class_name}消费处理处理异常【{$error['error']}】",$error);
//        }
            Goods::instance()->where('cid',$cid)->where('is_trade',0)->where('df',0)->update([
                'sync_off'    => 1
            ]);
        return Normal::returnCode(Normal::SUC,"处理完成");
    }
}